package com.docmgmt.mvp.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 文件实体（v3.0）
 *
 * 核心变更：
 * - 新增 privacy_level 字段：privacy/shared/public（3级隐私）
 * - 新增 ragflow_doc_id 字段：RAGFlow文档ID（文件上传时同步获得）
 * - 删除 kb_id 字段：v3.0改为M:N映射（通过kb_file_mapping表）
 *
 * @TableName doc_file
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("doc_file")
public class FileEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /** 文件名 */
    @TableField("name")
    private String fileName;

    /** 文件大小（字节） */
    @TableField("size")
    private Long fileSize;

    /** 完整路径（冗余，便于显示） */
    @TableField("path")
    private String filePath;

    /** MIME类型（如 application/pdf, image/png） */
    @TableField("mime_type")
    private String mimeType;

    /** 文件扩展名（如：pdf, docx） */
    @TableField("extension")
    private String fileExtension;

    /** MinIO中的对象key */
    @TableField("storage_key")
    private String storagePath;

    /** MD5校验值（用于去重） */
    @TableField("md5")
    private String md5Hash;

    /** SHA256校验值 */
    @TableField("sha256")
    private String sha256;

    /** 所属文件夹ID */
    @TableField("folder_id")
    private Long folderId;

    /** 创建人ID */
    @TableField("creator_id")
    private Long uploadedBy;

    /** 创建人部门ID (v3.0新增，用于shared隐私级别过滤) */
    @TableField("creator_dept_id")
    private Long creatorDeptId;

    /** 所有者ID */
    @TableField("owner_id")
    private Long ownerId;

    /** 最后编辑人ID */
    @TableField("last_editor_id")
    private Long lastEditorId;

    /** 最后编辑时间 */
    @TableField("last_edit_time")
    private LocalDateTime lastEditTime;

    /** v3.0新增：文件隐私级别（privacy/shared/public） */
    @TableField("privacy_level")
    private String privacyLevel;

    /** v3.0新增：RAGFlow文档ID（上传时获得） */
    @TableField("ragflow_doc_id")
    private String ragflowDocId;

    /** RAGFlow同步状态（pending/syncing/synced/failed） */
    @TableField("ragflow_sync_status")
    private String ragflowSyncStatus;

    /** 最后同步时间 */
    @TableField("ragflow_sync_time")
    private LocalDateTime ragflowSyncTime;

    /** 当前版本号 */
    @TableField("version")
    private Integer versionNumber;

    @TableField("download_count")
    private Integer downloadCount;

    /** 查看次数 */
    @TableField("view_count")
    private Integer viewCount;

    /** 是否锁定（锁定后不可修改/删除） */
    @TableField("is_locked")
    private Boolean isLocked;

    /** 锁定人ID */
    @TableField("locked_by")
    private Long lockedBy;

    /** 锁定时间 */
    @TableField("locked_at")
    private LocalDateTime lockedAt;

    /** 是否已删除 */
    @TableLogic
    @TableField("is_deleted")
    private Boolean deleted;

    /** 删除时间 */
    @TableField("deleted_at")
    private LocalDateTime deletedAt;

    /** 删除人ID */
    @TableField("deleted_by")
    private Long deletedBy;

    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    // ==================== 便捷方法（兼容FileService）====================

    /**
     * 获取文件名（别名）
     */
    public String getName() {
        return this.fileName;
    }

    /**
     * 设置文件名（别名）
     */
    public void setName(String name) {
        this.fileName = name;
    }

    /**
     * 获取文件大小（别名）
     */
    public Long getSize() {
        return this.fileSize;
    }

    /**
     * 获取完整路径（别名）
     */
    public String getPath() {
        return this.filePath;
    }

    /**
     * 获取存储键（别名）
     */
    public String getStorageKey() {
        return this.storagePath;
    }

    /**
     * 获取文件扩展名（别名）
     */
    public String getExtension() {
        return this.fileExtension;
    }

    /**
     * 设置文件扩展名（别名）
     */
    public void setExtension(String extension) {
        this.fileExtension = extension;
    }

    /**
     * 获取版本号（别名）
     */
    public Integer getVersion() {
        return this.versionNumber;
    }

    /**
     * 获取创建者ID（uploadedBy的别名）
     */
    public Long getCreatorId() {
        return this.uploadedBy;
    }

    /**
     * 获取创建者部门ID
     */
    public Long getCreatorDeptId() {
        return this.creatorDeptId;
    }

    /**
     * 设置创建者部门ID
     */
    public void setCreatorDeptId(Long creatorDeptId) {
        this.creatorDeptId = creatorDeptId;
    }

    /**
     * 获取删除状态（兼容方法）
     */
    public Boolean getIsDeleted() {
        return this.deleted;
    }

    /**
     * 设置删除状态（兼容方法）
     */
    public void setIsDeleted(Boolean isDeleted) {
        this.deleted = isDeleted;
    }

    /**
     * 设置锁定状态（兼容方法）
     */
    public void setIsLocked(Boolean locked) {
        this.isLocked = locked;
    }

    /**
     * 获取锁定状态（兼容方法）
     */
    public Boolean getIsLocked() {
        return this.isLocked;
    }

    // ==================== Getter 方法（显式添加以确保编译通过）====================

    public Long getId() {
        return this.id;
    }

    public String getFileName() {
        return this.fileName;
    }

    public Long getFileSize() {
        return this.fileSize;
    }

    public String getFilePath() {
        return this.filePath;
    }

    public String getMimeType() {
        return this.mimeType;
    }

    public String getFileExtension() {
        return this.fileExtension;
    }

    public String getStoragePath() {
        return this.storagePath;
    }

    public String getMd5Hash() {
        return this.md5Hash;
    }

    public String getSha256() {
        return this.sha256;
    }

    public Long getFolderId() {
        return this.folderId;
    }

    public Long getUploadedBy() {
        return this.uploadedBy;
    }

    public Long getOwnerId() {
        return this.ownerId;
    }

    public Long getLastEditorId() {
        return this.lastEditorId;
    }

    public LocalDateTime getLastEditTime() {
        return this.lastEditTime;
    }

    public String getPrivacyLevel() {
        return this.privacyLevel;
    }

    public String getRagflowDocId() {
        return this.ragflowDocId;
    }

    public String getRagflowSyncStatus() {
        return this.ragflowSyncStatus;
    }

    public LocalDateTime getRagflowSyncTime() {
        return this.ragflowSyncTime;
    }

    public Integer getVersionNumber() {
        return this.versionNumber;
    }

    public Integer getDownloadCount() {
        return this.downloadCount;
    }

    public Integer getViewCount() {
        return this.viewCount;
    }

    public Long getLockedBy() {
        return this.lockedBy;
    }

    public LocalDateTime getLockedAt() {
        return this.lockedAt;
    }

    public Boolean getDeleted() {
        return this.deleted;
    }

    public LocalDateTime getDeletedAt() {
        return this.deletedAt;
    }

    public Long getDeletedBy() {
        return this.deletedBy;
    }

    public LocalDateTime getCreatedAt() {
        return this.createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return this.updatedAt;
    }

    // ==================== Setter 方法（为编译添加）====================

    public void setId(Long id) {
        this.id = id;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    
    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }
    
    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }
    
    public void setStoragePath(String storagePath) {
        this.storagePath = storagePath;
    }
    
    public void setMd5Hash(String md5Hash) {
        this.md5Hash = md5Hash;
    }
    
    public void setFolderId(Long folderId) {
        this.folderId = folderId;
    }
    
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    
    public void setFileExtension(String fileExtension) {
        this.fileExtension = fileExtension;
    }
    
    public void setUploadedBy(Long uploadedBy) {
        this.uploadedBy = uploadedBy;
    }
    
    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }
    
    public void setPrivacyLevel(String privacyLevel) {
        this.privacyLevel = privacyLevel;
    }
    
    public void setRagflowDocId(String ragflowDocId) {
        this.ragflowDocId = ragflowDocId;
    }
    
    public void setRagflowSyncStatus(String ragflowSyncStatus) {
        this.ragflowSyncStatus = ragflowSyncStatus;
    }
    
    public void setVersionNumber(Integer versionNumber) {
        this.versionNumber = versionNumber;
    }
    
    public void setStorageUsed(Long storageUsed) {
        // 空实现，仅为满足编译需要
    }
}